package snake.utils;

import snake.common.Constant;
import snake.common.GameContextHolder;
import snake.enums.GameState;
import snake.model.Food;
import snake.model.Snake;

import java.awt.*;

public class GameUtils {
    public static void prompt(Graphics g) {
        String message = "";
        if (GameContextHolder.getContext().getState() == GameState.NOT_STATE) {
            message = "空格开始游戏";
        }
        if (GameContextHolder.getContext().getState() == GameState.PAUSED) {
            message = "游戏暂停，空格继续";
        }
        drawWord(g, message, Color.RED, new Font("黑体", Font.PLAIN, Constant.PROMPT_WORLD_SIZE), Constant.DEFAULT_WINDOW_WIDTH / 2 - message.length() * Constant.PROMPT_WORLD_SIZE / 2, Constant.DEFAULT_WINDOW_HEIGHT / 2 - Constant.PROMPT_WORLD_SIZE / 2);
    }

    public static void drawWord(Graphics g, String str, Color color, Font font, int x, int y) {
        g.setColor(color);
        g.setFont(font);
        g.drawString(str, x, y);
    }

    public static boolean isEatFood() {
        Snake snake = GameContextHolder.getContext().getSnake();
        Food food = GameContextHolder.getContext().getFood();
        return snake.getSnakeHead().x == food.x && snake.getSnakeHead().y == food.y;
    }

    public static boolean isGameOver() {
        Snake snake = GameContextHolder.getContext().getSnake();
        return snake.isEatBody() || snake.isOutOfBound();
    }
}
